<?php
/* OpenBIBLIO -- A library administration web interface
 * Copyright (C) 2002-2005 Fr&eacute;d&eacute;ric Descamps <lefred@tiscali.be>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

if(!(isset($_POST[submit_pwd])) and !(isset($_POST[submit2])))
{
   ?>
    <br><center>
    <form action=admin.php method=POST>
    <table>
    <tr><td>
    <?php echo _("Mot de passe superutilisateur"); ?> :
    </td><td>
    <input type=password name=rootpwd>
    </td></tr>
    </table>
    <input type=submit value=<?php echo _("Entrer"); ?> name=submit_pwd>
    <INPUT TYPE="hidden" NAME="user" value="<?php echo $user; ?>">
    <INPUT TYPE="hidden" NAME="action" value="<?php echo $action; ?>">
    </form>
    </center>
   <?php
}
else
{

 if(md5($_POST[rootpwd]) != get_rootpwd() and !(isset($_POST[submit2])))
 {
         echo "<CENTER><BR>";
         echo _("Le mot de passe du superuser n'est pas valide, recommencez!");
         echo "<BR><BR>";
         echo "<A href=\"admin.php?action=config\">";
         echo _("retour");
         echo "</A></CENTER>";
         include("includes/footer.inc");
         exit;
 }
 
 $sw = $_POST['sw'];    
    if ($_POST['rootpwd'] != $_POST['rootpwd2'] and (isset($_POST['sw'])))
    { 
      echo "<br><center><font color=red>";
      echo _("Les deux mots de passe ne correspondent pas !");
      echo "</font><br></center>";
      $sw=0;
    }
    if ($sw!=1)
    {
 
       $requete = "select * from config ";
        if(!($resultat = biblio_db_query($requete)))
        { print "PROBLEME : " .biblio_db_error(); }
        else 
        {
                while ($row = biblio_db_fetch_array($resultat)) 
	        {      
                        $config_title       = $row['title'];           
                        $config_logpath     = $row['logpath'];      
                        $config_picspath    = $row['picspath'];      
                        $config_coverspath  = $row['coverspath'];      
                        $config_rootpwd     = $row['rootpwd'];      
			$config_language    = $row['language'];
			$config_enable_soap = $row['enable_soap'];
			$config_client_soap = $row['client_soap'];
			$config_max_record  = $row['max_record'];
                }
         }
        ?>
        <CENTER><H3>
	<?php echo _("Configuration d'OpenBiblio"); ?>
	</H3>
        <FORM action=admin.php METHOD=POST>
        <TABLE BORDER=0>
        <tr>
        <td>
	<?php echo _("Titre"); ?>
	:</td><td><INPUT TYPE="text" NAME="title" size = 50 value="<?php echo $config_title; ?>"></td>
        </tr>
        <tr>
        <td>
	<?php echo _("R&eacute;pertoire des logs"); ?>
	:</td><td><INPUT TYPE="text" NAME="logpath" size = 50 value="<?php echo $config_logpath; ?>"></td>
        </tr>
        <tr>
        <td>
	<?php echo _("R&eacute;pertoire des photos"); ?>
	:</td><td><INPUT TYPE="text" NAME="picspath" size = 50 value="<?php echo $config_picspath; ?>"></td>
        </tr>
        <tr>
        <td>
	<?php echo _("R&eacute;pertoire des couverures"); ?>
	:</td><td><INPUT TYPE="text" NAME="coverspath" size = 50 value="<?php echo $config_coverspath; ?>"></td>
        </tr>
        <tr>
        <td>
	<?php echo _("Mote de passe du superutilisateur"); ?>
	:</td><td><INPUT TYPE="password" NAME="rootpwd" size = 10></td>
        </tr>
        <tr>
        <td>
	<?php echo _("Mote de passe du superutilisateur (x2)"); ?>
	:</td><td><INPUT TYPE="password" NAME="rootpwd2" size = 10></td>
        </tr>
        <tr>
        <td>
	<?php echo _("Langue"); ?>
	:</td><td>
	<select name=language>
	<option value="fr_FR">fr_FR
	<?php
	$handle = opendir('locale');
	while (false !== ($file = readdir($handle))) 
	{
	       if ($file != "." and $file != "..")
	       {
	         if ($file == $config_language) $str="selected";
		 else $str="";
	         echo "<option value=$file $str>$file";
	       }
	}
 	closedir($handle);
	?>
	</select>
	</td>
        </tr>
        <tr>
        <td>
	<?php echo _("Activer SOAP:<br><i><small>(PHP5 seulement)</small></i>"); ?>
	</td><td>
	<select name="enable_soap">
	<option value=true><?php echo _("oui"); ?>
	<option value=false <?php if ($config_enable_soap == "false") echo "selected"; ?>><?php echo _("non"); ?>
	</select>
	</td>
        </tr>
        <tr>
        <td>
	<?php echo _("Url du service SOAP"); ?>
	:</td><td><INPUT TYPE="text" NAME="client_soap" size = 50 value="<?php echo $config_client_soap; ?>"></td>
        </tr>
        <tr>
        <td>
	<?php echo _("Nombre d'enregistrements<br>par page en mode recherche"); ?>
	:</td><td><INPUT TYPE="text" NAME="max_record" size = 3 value="<?php echo $config_max_record; ?>"></td>
        </tr>
        </TABLE><BR>
        <INPUT TYPE="hidden" NAME="user" value="<?php echo $user; ?>">
        <INPUT TYPE="hidden" NAME="action" value="<?php echo $action; ?>">
        <INPUT TYPE="hidden" NAME="type" value="<?php echo $type; ?>">
        <INPUT TYPE="hidden" NAME="sw" value="1">
        <INPUT TYPE="hidden" NAME="id" value="<?php echo $id; ?>">        
        <input type="Submit" name=submit2 value="
	<?php echo _("Enregistrer"); ?>
	">
        </FORM>
        </CENTER>
        <?php
    }   
    else
    {     
      if (strlen($_POST['rootpwd']) == 0) $pwd = get_rootpwd();
      else $pwd = md5($_POST['rootpwd']);
      $requete = "update config set title='". $_POST['title'] 
               . "', logpath='". $_POST['logpath']
               . "', picspath='". $_POST['picspath']
               . "', coverspath='". $_POST['coverspath']
               . "', rootpwd='". $pwd
               . "', language='". $_POST['language']
               . "', enable_soap='". $_POST['enable_soap']
               . "', max_record='". $_POST['max_record']
               . "', client_soap='". $_POST['client_soap']. "';";
      if(!($resultat = biblio_db_query($requete)))
      { echo _("PROBLEME : ") .biblio_db_error() ."<br>$requete"; exit;}  
      put_log(3,$requete,$user);
      echo "<CENTER><BR>";
      echo _("La configuration a &eacute;t&eacute; enregistr&eacute;e.");
    } 
}
?>
</center>
<br><br>
<div>
<span id=left-text>
<A HREF="admin.php?menu=1">
<?php echo _("retour menu administration"); ?>
</A><BR>
<A HREF="index.php">
<?php echo _("retour menu principal"); ?>
</A></span>
</div>
<br>
